/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tool;

import entities.Fantasyleague;
import entities.Fantasyuser;
import java.util.Enumeration;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author The Lunatics
 */
public class Session {

    public static HttpSession GetSession() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
        Enumeration e = session.getAttributeNames();
        while (e.hasMoreElements()) {
            String attr = (String) e.nextElement();
            System.err.println("      attr  = " + attr);
            Object value = session.getAttribute(attr);
            System.err.println("      value = " + value);
        }
        return session;
    }

    public static String GetLeagueIdFromContext() {
        HttpSession session = GetSession();
        Fantasyleague league = (Fantasyleague) session.getAttribute("Fantasyleague");
        return league.getId().toString();
    }

    public static String GetUserIdFromContext() {
        HttpSession session = GetSession();
        Fantasyuser user = (Fantasyuser) session.getAttribute("Fantasyuser");
        return user.getId().toString();
    }
}
